package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.wemedia.service.WmNewsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 文章管理控制
 */
@RestController
@RequestMapping("/api/v1/news")
@Slf4j
@RequiredArgsConstructor
public class WmNewsController {

    //Service
    private final WmNewsService wmNewsService;


    /**
     * 查看文章列表
     * @param wmNewsPageReqDto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult findList(@RequestBody WmNewsPageReqDto wmNewsPageReqDto) {
        log.info("查看文章列表...{}", wmNewsPageReqDto);

        return wmNewsService.findList(wmNewsPageReqDto);
    }


    /**
     * 文章发布修改或保存为草稿
     * @param
     * @return
     */
    @PostMapping("/submit")
    public ResponseResult submitNews(@RequestBody WmNewsDto wmNewsDto) {
        log.info("文章提交，{}",wmNewsDto);

        return wmNewsService.submitNews(wmNewsDto);
    }


    /**
     * 查看文章详情
     * @param id
     * @return
     */
    @GetMapping("/one/{id}")
    public ResponseResult findNewsContent(@PathVariable Integer id) {

        log.info("查看文章详情...{}",id);

        return wmNewsService.findNewContent(id);
    }


    /**
     * 删除文章
     * @param id
     * @return
     */
    @GetMapping("/del_news/{id}")
    public ResponseResult deleteNews(@PathVariable Integer id) {

        log.info("删除文章...{}",id);

        return wmNewsService.removeNews(id);
    }


    /**
     * 文章上下架
     * @param wmNewsDto
     * @return
     */
    @PostMapping("/down_or_up")
    public ResponseResult downOrUpNews(@RequestBody WmNewsDto wmNewsDto) {

        log.info("文章上下架...{}",wmNewsDto);

        return wmNewsService.downOrUpNews(wmNewsDto);
    }



}





























